package com.sptpc.demo1.service.impl;

import com.sptpc.demo1.model.Student;
import com.sptpc.demo1.repository.StudentRepository;
import com.sptpc.demo1.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

    @Service
    public class StudentJpaService implements IStudentService {
        @Autowired
        private StudentRepository studentRepository;

        @Override
        public List<Student> getAllStudent() {
            return studentRepository.findAll();
        }

        @Override
        public void addNewStudent(Student student) {
            studentRepository.save(student);
        }

        @Override
        public Student getStudnetById(Long id) {
            return studentRepository.findById(id).orElse(null);
        }

        @Override
        public void updataStudent(Student student) {
            studentRepository.save(student);
        }

        @Override
        public void deleteByid(Long id) {
            studentRepository.deleteById(id);
        }


    }